<template>
  <div v-loading="loading" :element-loading-text="loadingText" class="audit">
    <div class="bread-box but20">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item class="btn-green" style=" color: #3DC094;" @click.native="goBack">成品配置</el-breadcrumb-item>
        <el-breadcrumb-item>成品配置单</el-breadcrumb-item>
        <el-breadcrumb-item>审核</el-breadcrumb-item>
      </el-breadcrumb>
      <div>
        <el-button size="mini" @click="clickBack">取消</el-button>
        <el-button type="primary" @click="confirmHandle">确认</el-button>
      </div>
    </div>
    <div style="margin-top: 20px;">
      <el-form ref="form" :model="formData" :rules="formRules" label-width="80px">
        <el-form-item prop="reviewResult" label="审核结果" :rules="[{ required: true, message: '请选择审核结果' }]">
          <el-select v-model="formData.reviewResult" placeholder="审核结果" @change="resultChange">
            <el-option value="1" label="同意" />
            <el-option value="0" label="不同意" />
          </el-select>
        </el-form-item>
        <el-form-item prop="reviewAdvice" label="审核意见" :rules="[{ required: formData.reviewResult === '0', message: '请输入审核意见' }]">
          <el-input v-model="formData.reviewAdvice" type="textarea" :autosize="{minRows:3}" maxlength="1024" placeholder="审核意见" />
        </el-form-item>
      </el-form>
    </div>
    <Detail is-audit @getDetail="getDetailData" />
  </div>
</template>
<script>
import Detail from './detail'
import { auditConfigEditData } from '@/api/proConfig'
export default {
  name: 'Audit',
  components: {
    Detail
  },
  data() {
    return {
      loading: false,
      loadingText: '',
      formData: {
        reviewResult: '',
        reviewAdvice: ''
      }
      // formRules: {
      //   reviewResult: [{ required: true, message: '请选择审核结果', trigger: 'change' }],
      //   reviewAdvice: [{ required: false, message: '请填写审核意见', trigger: 'change' }]
      // }
    }
  },
  created() {
    this.loading = true
    this.loadingText = '加载中'
  },
  methods: {
    // resultChange(v) {
    //   const fb = this.formRules.reviewAdvice[0]
    //   if (v === '0') {
    //     this.$set(fb, 'required', true)
    //   } else {
    //     this.$set(fb, 'required', false)
    //   }
    //   this.$refs.form.clearValidate('reviewAdvice')
    // },
    getDetailData(data) {
      this.formData = data
      this.$set(this.formData, 'reviewAdvice', '')
      this.$set(this.formData, 'reviewResult', '')
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
      })
      this.loading = false
    },
    confirmHandle() {
      this.$refs.form.validate(validate => {
        if (validate) {
          this.loading = true
          this.loadingText = '系统处理中'
          if (this.formData.reviewResult === '1') {
            this.formData.schedule = 'C'
          } else {
            this.formData.schedule = 'A'
          }
          this.formData.productConfigOutpicDtos = this.formData.configOutPicDtos
          auditConfigEditData(this.formData).then(res => {
            if (res.success) {
              this.$message.success('操作成功')
              this.clickBack()
            }
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    clickBack() {
      this.$store.dispatch('views/goBack')
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
